package com.tiancheng.trade.payment.channel.umsmop.request;

import com.tiancheng.trade.payment.channel.umsmop.OpenApiRequest;
import com.tiancheng.trade.payment.channel.umsmop.response.TokenResponse;
import com.tiancheng.trade.payment.channel.umsmop.util.OpenTokenUtil;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

/**
 * @ClassName UmsMopTokenRequest
 * @Description TODO
 * @Author kellen
 * @Date 2024/12/8 12:02
 */
public class UmsMopTokenRequest implements OpenApiRequest<TokenResponse> {
    /**
     * 开放平台开发者id
     */
    private String appId;
    /**
     * 开放平台开发者key
     */
    private String appKey;
    /**
     * 时间戳
     */
    private String timestamp;
    /**
     * 随机数
     */
    private String nonce;
    /**
     * 加密方法
     */
    private String signMethod;
    /**
     * SHA256签名字符
     */
    private String signature;

    public Class<TokenResponse> responseClass() {
        return TokenResponse.class;
    }

    public String apiVersion() {
        return "v2";
    }   //新入驻商户需要使用v2方式

    public String apiMethodName() {
        return "获取开放平台token";
    }

    public String serviceCode() {
        return "/token/access";
    }

    public boolean needToken() {
        return false;
    }

    public UmsMopTokenRequest(String appId, String appKey) {
        this.appId = appId;
        this.appKey = appKey;
        this.timestamp = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
        this.nonce = UUID.randomUUID().toString();
        this.signMethod = "SHA256";
        this.signature = OpenTokenUtil.generateSignature(getAppId(), getTimestamp(), getNonce(), getAppKey());
    }

    public String getAppId() {
        return appId;
    }

    public void setAppId(String appId) {
        this.appId = appId;
    }

    public String getAppKey() {
        return appKey;
    }

    public void setAppKey(String appKey) {
        this.appKey = appKey;
    }

    public String getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(String timestamp) {
        this.timestamp = timestamp;
    }

    public String getNonce() {
        return nonce;
    }

    public void setNonce(String nonce) {
        this.nonce = nonce;
    }

    public String getSignMethod() {
        return signMethod;
    }

    public void setSignMethod(String signMethod) {
        this.signMethod = signMethod;
    }

    public String getSignature() {
        return signature;
    }

    public void setSignature(String signature) {
        this.signature = signature;
    }
}
